home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / qwindows.arc / WINDOW.8 < prev    next >
Encoding:
Text File  |  1987-05-06  |  10.0 KB  |  286 lines

  1. ;This is a procedure callable from QBasic to draw a window on the screen.
  2. ;The left & right column, top & bottom row, attribute & frame type, and explode
  3. ;& shadow parameters are passed from Basic in that order as 4 words.
  4.  
  5. Name      Makewind            ;Name used at link time
  6. Public    Makewind            ;Only module name is public
  7.  
  8. Makewind: org       0         ;So can be linked
  9.  
  10. Spc       equ       20h
  11. Period    equ       800       ;Initial period for sound
  12.  
  13.           jmp  short Getpara  ;Get parameters
  14.  
  15. Parameters:
  16. Explode   db        1         ;1=>explode window from center
  17. Shadow    db        1         ;1=>shadow window when done
  18. Attr      db        37        ;Attribute byte for window
  19. Frame     db        1         ;Frame type; 0=>line, 1=>double line
  20. Urow      db        2         ;Upper row of window
  21. Lrow      db        23        ;Lower row of window
  22. Lcol      db        10        ;Left column of window
  23. Rcol      db        70        ;Right column of window
  24. Freq      dw        Period    ;Count for sound
  25. Row1      db        ?         ;Current upper row
  26. Row2      db        ?         ;Current lower row
  27. Col1      db        ?         ;Current left column
  28. Col2      db        ?         ;Current right column
  29. Mcol      db        ?         ;Difference between Lcol and Rcol
  30. Mrow      db        ?         ;Difference between Urow and Lrow
  31. Flag      db        0         ;0=>no growth
  32. Rows      db        ?         ;Number of rows to do
  33. Vpage     db        ?         ;Current video page
  34. Vidmem    dw        0B800h    ;Video page 1 segment
  35. Msg1:     db   'Not in a color mode now.$'   ;Error message
  36. Table:                        ;Table of box chars
  37.           db   '┌─┐│ │└─┘'    ;Single line chars
  38.           db   '╔═╗║ ║╚═╝'    ;Double line chars
  39.           db   '╒═╕│ │╘═╛'    ;Double horiz, single vert
  40.           db   '╓─╖║ ║╙─╜'    ;Single horiz, double vert
  41.  
  42. Getpara:                      ;Get parameters from stack
  43.           push      bp
  44.           mov       bp,sp
  45.           push      ds
  46.           push      es
  47.           push      cs        ;es=cs
  48.           pop       es
  49.           cld                 ;Set to inc si & di
  50.           add       bp,6      ;Point to 1st parameter address
  51.           mov       cx,4      ;4 parameters to get
  52.           mov       di,Parameters ;Point to parameter storage area
  53. A0:       mov       si,[bp]   ;Get address of parameter
  54.           movsw               ;Get the parameter
  55.           add       bp,2      ;Point to next passed parameter address
  56.           loop      A0        ;Get all 4 parameters
  57.           push      cs        ;ds=cs
  58.           pop       ds
  59.  
  60. ;Get current video mode and page
  61.           mov  ah,15     ;Get current video mode
  62.           int  10h
  63.           mov  Vpage,bh  ;Save page
  64.           cmp  al,2      ;Mode 2?
  65.           je   Color     ;Yes
  66.           cmp  al,3      ;Mode 3?
  67.           je   Color     ;Yes
  68.           mov  dx,Msg1   ;No, print message
  69.           mov  ah,9
  70.           int  21h
  71. Exit:                    ;Return to Basic
  72.           pop  es
  73.           pop  ds
  74.           pop  bp
  75.           retf  8         
  76.           
  77. Color:                   ;Find video memory.
  78.           mov  bl,0      ;bx=page offset
  79.           add  bx,Vidmem ;Add page 0 address
  80.           mov  Vidmem,bx ;Save it
  81.           mov  es,bx     ;Set for dest segment
  82.  
  83. ;Find Row1, Row2, Col1, Col2, Mcol, and Rcol
  84.           mov  al,Lrow
  85.           sub  al,Urow
  86.           shr  al,1
  87.           mov  Mrow,al
  88.  
  89.           mov  al,Rcol
  90.           sub  al,Lcol
  91.           shr  al,1
  92.           mov  Mcol,al
  93.  
  94.           mov  al,Urow
  95.           add  al,Mrow
  96.           mov  Row1,al
  97.  
  98.           mov  al,Lrow
  99.           sub  al,Mrow
  100.           mov  Row2,al
  101.  
  102.           mov  al,Lcol
  103.           add  al,Mcol
  104.           mov  Col1,al
  105.  
  106.           mov  al,Rcol
  107.           sub  al,Mcol
  108.           mov  Col2,al
  109. ;See if window should explode
  110.           cmp  Explode,0 ;Explode?
  111.           je   Nosound   ;No
  112.           in   al,61h    ;Enable speaker
  113.           or   al,3
  114.           out  61h,al
  115.           jmp  short Grow
  116. Nosound:  mov  al,Urow   ;Set to max dimensions
  117.           mov  Row1,al
  118.           mov  al,Lrow
  119.           mov  Row2,al
  120.           mov  al,Lcol
  121.           mov  Col1,al
  122.           mov  al,Rcol
  123.           mov  Col2,al
  124.  
  125. Grow:                    ;Grow the window from its center point found above.
  126.           mov  Flag,0    ;Assume no growth
  127.           call Delay     ;Wait for next Vert retrace
  128.           call Dowindow  ;Draw window
  129.           cmp  Explode,0 ;Explode?
  130.           je   A5        ;No
  131.           call Gensnd    ;Make a sound
  132.           mov  al,Row1   ;Get current upper row
  133.           cmp  al,Urow   ;= upper row?
  134.           je   A1        ;Yes
  135.           dec  Row1      ;Grow up
  136.           or   Flag,1    ;=> growth
  137. A1:       mov  al,Row2   ;Get current lower row
  138.           cmp  al,Lrow   ;= lower row?
  139.           je   A2        ;Yes
  140.           inc  Row2      ;Grow down
  141.           or   Flag,1    ;=> growth
  142. A2:       mov  al,Col1   ;Get current left column
  143.           cmp  al,Lcol   ;= left column?
  144.           je   A3        ;Yes
  145.           dec  Col1      ;Grow left
  146.           or   Flag,1    ;=> growth
  147. A3:       mov  al,Col2   ;Get current right column
  148.           cmp  al,Rcol   ;= right column?
  149.           je   A4        ;Yes
  150.           inc  Col2      ;Grow right
  151.           or   Flag,1    ;=> growth
  152. A4:       cmp  Flag,0    ;Was there growth?
  153.           je   A5        ;No
  154.           jmp  Grow      ;and do next growth
  155.  
  156. A5:       in   al,61h    ;Disable speaker
  157.           and  al,0FCh
  158.           out  61h,al
  159.           mov  Freq,Period ;Reset period for next time
  160.           cmp  Shadow,0  ;Make a shadow?
  161.           je   A6        ;No
  162.           mov  al,Lcol
  163.           sub  al,2
  164.           mov  Col1,al
  165.           mov  al,Urow
  166.           inc  al
  167.           mov  Row1,al
  168.           mov  al,Lrow
  169.           sub  al,Urow
  170.           mov  Rows,al
  171.           call Findmem   ;Find offset of shadow
  172.           mov  ah,0      ;Set attr for black on black
  173. D2:       push di
  174.           stosw
  175.           stosw
  176.           pop  di
  177.           add  di,160
  178.           dec  Rows
  179.           jne  D2
  180.           mov  ch,0
  181.           mov  cl,Rcol
  182.           sub  cl,Lcol
  183.           call Dorow
  184. A6:       jmp  Exit
  185.  
  186. Dowindow:                ;Find offset to upper left corner of current box.
  187.           call Findmem   ;Find offset to start of window
  188.           push di        ;Save start position
  189.           mov  al,Row2   ;Get rows to do
  190.           sub  al,Row1
  191.           inc  al        ;= rows to do
  192.           cmp  al,1      ;At least 2 rows?
  193.           ja   B0        ;Yes
  194.           mov  al,2      ;No, set for 2 Rows
  195. B0:       mov  Rows,al   ;Save it
  196.           mov  ch,0      ;Get current width-1 in cx
  197.           mov  cl,Col2
  198.           sub  cl,Col1
  199.           cmp  cl,2      ;Aty least 3 columns wide?
  200.           ja   Dotop     ;Yes
  201.           inc  Col2      ;No, adjust columns
  202.           dec  Col1
  203.           pop  di
  204.           jmp  Dowindow  ;and recompute
  205. Dotop:                   ;Do top of box.
  206.           push cx        ;Save width
  207.           mov  al,Frame  ;Get frame type
  208.           mov  ah,9      ;6 bytes/frame type in Table
  209.           mul  ah        ;Offset to frame chars
  210.           mov  bx,Table  ;Point to frame char table
  211.           add  bx,ax     ;Point to border char type
  212.           mov  ah,Attr   ;Get attribute (color)
  213.           call Dorow     ;Do the row
  214.           dec  Rows      ;=rows left to do
  215.           cmp  Rows,1    ;=1?
  216.           je   Dobottom  ;Yes, skip sides of box
  217. Dosides:                 ;Do sides of box.
  218.           pop  cx        ;Get width-1
  219.           pop  di        ;Get start position
  220.           add  di,160    ;Next row
  221.           push di
  222.           push cx        ;Save for next time
  223.           push bx        ;Save place in table
  224.           call Dorow     ;Do the row
  225.           pop  dx        ;Get 1st middle char address
  226.           dec  Rows      ;=rows left to do
  227.           cmp  Rows,1    ;=1?
  228.           je   Dobottom  ;Yes
  229.           mov  bx,dx     ;1st side char address in bx
  230.           jmp  Dosides   ;and do next row
  231. Dobottom:                ;Do bottom of box.
  232.           pop  cx        ;Get width-1
  233.           pop  di
  234.           add  di,160    ;Next row
  235.           call Dorow     ;Do the row
  236.           ret            ;and return
  237.  
  238. Dorow:                   ;Do a row on the screen.
  239.           mov  al,[bx]   ;Get upper left char
  240.           stosw          ;Save in video memory
  241.           inc  bx        ;Next char
  242.           mov  al,[bx]   ;Get middle chars
  243. D1:       stosw          ;Save to video memory
  244.           loop D1        ;Do all middle chars
  245.           inc  bx        ;Right char
  246.           mov  al,[bx]   ;Get right char
  247.           stosw          ;Save to video memory
  248.           inc  bx
  249.           ret            ;and return
  250.  
  251. Findmem:                 ;Find the offset of the current Row1,Col1
  252.           mov  al,Row1   ;Get current row
  253.           dec  al        ;Since rows start with 1
  254.           mov  ah,160    ;bytes/row
  255.           mul  ah        ;Offset to start of row
  256.           mov  di,ax     ;in di
  257.           mov  ah,0      ;Get current left column in ax
  258.           mov  al,Col1
  259.           dec  al        ;Since cols start with 1
  260.           shl  ax,1      ;Multiply by 2, since 2 bytes/char
  261.           add  di,ax     ;Add column offset
  262.           ret
  263.  
  264. Delay:                   ;Wait for the next vertical retrace.
  265.           mov  dx,3DAh   ;Video status port
  266. C0:       in   al,dx     ;Get status
  267.           test al,8      ;Vertical retrace?
  268.           jne  C0        ;Yes, wait till done
  269. C1:       in   al,dx     ;Get status
  270.           test al,8      ;Vertical retrace?
  271.           je   C1        ;No, wait for retrace
  272.           ret            ;and return
  273.  
  274. Gensnd:                  ;Make an increasing pitch sound as window grows.
  275.           mov  al,0B6h   ;Let the timer know we want to program it
  276.           out  43h,al
  277.           mov  ax,Freq   ;Send low then high byte to timer
  278.           push ax
  279.           out  42h,al
  280.           mov  al,ah
  281.           out  42h,al
  282.           pop  ax
  283.           sub  ax,20
  284.           mov  Freq,ax
  285.           ret
  286.